//
//  ValidatePwd.m
//  DaoZiJinFu
//
//  Created by woker on 16/8/19.
//  Copyright © 2016年 iwoker. All rights reserved.
//

#import "ValidatePwd.h"

@implementation ValidatePwd

+ (instancetype)showView:(UIView *)view {
    ValidatePwd *validatePwd = [[[NSBundle mainBundle] loadNibNamed:@"ValidatePwd" owner:nil options:nil] lastObject];
    [view addSubview:validatePwd];
    
    validatePwd.frame = view.frame;
    
    [validatePwd readjustView];
    
    return validatePwd;
}

- (void)readjustView {
    _alert.layer.masksToBounds = YES;
    _alert.layer.cornerRadius = 10;
    _pwdText.layer.borderColor = [UIColor lightGrayColor].CGColor;
    _pwdText.layer.borderWidth = 1;
    _pwdText.layer.cornerRadius = BTN_RADIUS;
    _pwdText.layer.masksToBounds = YES;
    NSMutableString *mobileStr = [NSMutableString stringWithString:DZUserInfo.userInfo.mobile];
    [mobileStr replaceCharactersInRange:NSMakeRange(3, 4) withString:@"****"];
    _telLabel.text = mobileStr;
}

- (IBAction)sureBtnClick:(id)sender {
    JSSHOWHUD;
    DZRequestUtil *request = [[DZRequestUtil alloc] init];
    request.requestUrl = @"User/checkPwd";
    request.params = @{@"pwd":_pwdText.text};
    [DZNetAPI request:request success:^(id response) {
        JSHIDEHUD;
        DZResponse *model = [DZResponse mj_objectWithKeyValues:response];
        if (model.rt == 1) {
            [self removeFromSuperview];
            if (_validateType == ValidatePwdCloseGesture) {
                [[NSNotificationCenter defaultCenter]postNotificationName:@"closeGestureOperation" object:self];
            } else if (_validateType == ValidatePwdSettingGesture) {
                [[NSNotificationCenter defaultCenter]postNotificationName:@"settingGestureOperation" object:self];
            }
        }else{
            JSSHOW(model.msg);
        }
    } failure:^(NSError *error) {
        JSSHOW(LOAD_FAIL_TIP);
    }];
}

- (IBAction)cancelBtnClick:(id)sender {
    [self removeFromSuperview];
}

- (void)awakeFromNib {
    [super awakeFromNib];
}

@end
